package com.kaifamiao.io.d0922;

import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class ReaderDemo {

    public static void main(String[] args) {

        String path = "d:/io/reader-gbk.txt";
        try (FileReader reader = new FileReader(path, Charset.forName("gbk"));) {
//            FileReader reader1 = new FileReader(new File(path));

            if (Charset.isSupported("gbk")){
                Charset.forName("gbk");
            }

            char[] chs = new char[2];
            int len = -1;

//            while( (len = reader.read(chs)) != -1 ){
//                System.out.print(new String(chs, 0, len));
//            }

            int c = -1;
            while( (c = reader.read()) != -1){
                System.out.print((char)c);
            }



//            int c = reader.read();
//            System.out.println((char)c);
//
//            char[] chs = new char[2];
//            int len = reader.read(chs);
//
//            System.out.println(Arrays.toString(chs));
//
//            len = reader.read(chs, 0, 1);
//            System.out.println(Arrays.toString(chs));




        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
